var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
// 定义一个数值和字符串的联合类型
var objNum = [1, 2, '1', '2'];
console.log(objNum);
// 定义一个类型断言
var dyarr = [1, 2, 3, 4];
var dy = dyarr.length;
console.log(dy);
// 定义一个 void 实现函数的无返回值
function fnc() {
    console.log('努力加油敲代码');
}
fnc();
// 定义一个 never 的函数
function infiniteLoop() {
    while (true) {
    }
}
// 分别定义 es5 和 ts 的函数定义
//  对应于ES5中的函数声明法定义方式，ts中需要定义函数的返回值类型
// 定义函数时， 分别实现参数类型、剩余参数、默认参数
// 可选参数 ?   代表可有可无
function fnkx(a, b) {
    if (b) {
        return console.log(a + b);
    }
    else {
        return console.log(a);
    }
}
fnkx(1);
//参数类型
function fn(a, b) {
    return console.log(a + b);
}
fn(1, 2);
// 默认参数
function fn1(a1, b1) {
    if (b1 === void 0) { b1 = 'b1'; }
    return console.log(a1 + ' ' + b1);
}
fn1('a1');
//剩余参数 
function buildName(firstName) {
    var restOfName = [];
    for (var _i = 1; _i < arguments.length; _i++) {
        restOfName[_i - 1] = arguments[_i];
    }
    return console.log(firstName + " " + restOfName.join(" "));
}
buildName("Joseph", "Samuel", "Lucas", "MacKinzie");
// 实现一个函数重载
var suits = ["hearts", "spades", "clubs", "diamonds"];
function pickCard(x) {
    if (typeof x == "object") {
        var pickedCard = Math.floor(Math.random() * x.length);
        return pickedCard;
    }
    else if (typeof x == "number") {
        var pickedSuit = Math.floor(x / 13);
        return { suit: suits[pickedSuit], card: x % 13 };
    }
}
var myDeck = [{ suit: "diamonds", card: 2 }, { suit: "spades", card: 10 }, { suit: "hearts", card: 4 }];
var pickedCard1 = myDeck[pickCard(myDeck)];
console.log("card: " + pickedCard1.card + " of " + pickedCard1.suit); //card: 4 of hearts
var pickedCard2 = pickCard(15);
console.log("card: " + pickedCard2.card + " of " + pickedCard2.suit); // card: 2 of spades
//•	在 ts 中定义一个类并实现继承
var Animal = /** @class */ (function () {
    function Animal() {
    }
    Animal.prototype.move = function (distanceInMeters) {
        if (distanceInMeters === void 0) { distanceInMeters = 0; }
        console.log("Animal moved ".concat(distanceInMeters, "m."));
    };
    return Animal;
}());
var Dog = /** @class */ (function (_super) {
    __extends(Dog, _super);
    function Dog() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Dog.prototype.bark = function () {
        console.log('Woof! Woof!');
    };
    return Dog;
}(Animal));
var dog = new Dog();
dog.bark();
dog.move(10);
dog.bark();
